<?php

namespace App\Validate\Web;

use App\Validate\BaseValidate;
use App\Http\Models\ZtkUser;
use Illuminate\Support\Facades\Auth;

class UserRepassValidate extends BaseValidate
{
    protected $rules = [];// 规则

    protected $message = [];// 自定义消息

    public function __construct($request)
    {
        parent::__construct($request);

        $this->rules = [
            'old_password' => 'required',
            'password' => 'required|confirmed',
            'password_confirmation' => 'required',
        ];
        $this->message = [
            'old_password.required' => '请输入当前密码',
            'password.required' => '请输入密码',
            'password_confirmation.required' => '请输入确认密码',
            'password.confirmed' => '两次输入密码不一致',
        ];
    }

    protected function customValidate()
    {
        $old_password = $this->requestData['old_password'];

        $user = ZtkUser::select('password')->find(Auth::id());
        if(!\Hash::check($old_password, $user->password)){
            $this->validator->errors()->add('old_password', '当前密码不正确');
            return false;
        }

    }
}
